//==================================================================
//  Copyright (C) 2006  Davide Pasca
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//==================================================================
///
///
///
///
///
//==================================================================

#include "stdafx.h"

#include "rendm5d_texture.h"

//==================================================================
using namespace M5D;

//==================================================================
RendM5D::Texture::Texture( M5D::Texture *mtexp, RendDevice *rdevicep ) :
	_mtexp(mtexp),
	_rdevicep(rdevicep),
	TextureBase( mtexp->GetImageBase(), rdevicep )
{
	_mtexp->_userdatap = (void *)this;
}

//==================================================================
RendM5D::Texture::~Texture()
{
}

//==================================================================
void RendM5D::Texture::SelectTexture()
{
	if ( _mtexp.needs_update()  )
	{
		TextureBase::UpdateTexture();
	}

	_rdevicep->_DrawState.SetTexture( this );
	_rdevicep->_DrawState.SetTextureFilter( 0, PSYSGFX::TEXFILTERTYPE_MIN, _mtexp->_filter_mode );
	_rdevicep->_DrawState.SetTextureFilter( 0, PSYSGFX::TEXFILTERTYPE_MAX, _mtexp->_filter_mode );
	_rdevicep->_DrawState.SetTextureFilter( 0, PSYSGFX::TEXFILTERTYPE_MIP, _mtexp->_filter_mode );

	_rdevicep->_DrawState.SetTextureCoordAddr( 0, PSYSGFX::TEXADDRTYPE_S, _mtexp->_s_addr_mode );
	_rdevicep->_DrawState.SetTextureCoordAddr( 0, PSYSGFX::TEXADDRTYPE_T, _mtexp->_t_addr_mode );
}
